﻿#ifndef QLYAVFRAME_H
#define QLYAVFRAME_H
#include <QFile>
#include <QImage>
#include <QVideoFrame>
extern "C" {
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
}

class QlyAVFrame
{
public:
    QlyAVFrame();
    QlyAVFrame(int width, int height, AVPixelFormat format);
    QlyAVFrame(AVFrame *p);
    ~QlyAVFrame();
    QlyAVFrame(const QlyAVFrame &source);
    bool getBuffer(AVPixelFormat format, int width, int height);
    QlyAVFrame & operator= (const QlyAVFrame & source);

    AVPixelFormat format() const;
    bool buildFromQImage(const QImage &image, AVPixelFormat format, int pts);
    bool buildFromQVideoFrame(QVideoFrame &videoFrame, AVPixelFormat format, int pts);
    QImage toQImage(QImage::Format format);
    bool toQImage(QImage &image);
    AVFrame	* ptr() {return pFrame;}
    const AVFrame * ptr() const {return pFrame;}
    void reset();

    AVFrame	*pFrame = nullptr;
};

Q_DECLARE_TYPEINFO(QlyAVFrame, Q_MOVABLE_TYPE);

#endif // QLYAVFRAME_H

